import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import navi from './components/navigatebar.vue'
import tab_bar from './components/tab_bar.vue'
import {req} from './assets/js/ajax'
import axios from 'axios'
import qs from 'qs'
import wjh from '@/assets/js/wjh'
import VueSocketIO from 'vue-socket.io'
// import lhl from '@/api/lhl'
// Vue.prototype.$lhl=lhl

const app =createApp(App)
console.log(process.env.NODE_ENV);
console.log(process.env.VUE_APP_API_URL);
window.wjh=wjh
window.router=router
app.config.globalProperties.$ajax=req
axios.defaults.baseURL = '/';
//app.config.globalProperties.$axios=axios
app.config.globalProperties.$qs=qs
app.config.globalProperties.$time=(time)=>{
  let date=0
  if(time){
    date=new Date(time*1000)
  }else{
    date=new Date()
  }
  
  let year=date.getFullYear()
  let mouth=date.getMonth()+1
  let day=date.getDate()
  return `${year}-${mouth}-${day}`
}
app.config.globalProperties.$imgErr=(e)=>{
    let img = e.srcElement;
    img.src = require("/public/img/err.png");
    img.onerror = null;
}
app.directive(
    'aspectfill', {
      // 指令的定义
      mounted(el) {
        el.style.overflow='hidden'
        el.style.display='flex'
        el.style.justifyContent='center'
        el.style.alignItems='center'
        var img_url = el.getAttribute('src')+'?'+Date.parse(new Date());
        // 创建对象
        var img = new Image();
        // 改变图片的src
        img.src = img_url;
        // 定时执行获取宽高
        var check = function(){
          if(img.width>0 || img.height>0){
            let img1=document.createElement('img')
            img1.setAttribute('src',el.getAttribute('src'))
            if(img.width>=img.height){
              img1.setAttribute('height','100%')
            }else{
              img1.setAttribute('width','100%')
            }
            el.appendChild(img1)
            clearInterval(set);
          }
        };
          
        var set = setInterval(check,40);
          
        // 加载完成获取宽高
        img.onload = function(){
        
        };
      }
    }
)

app.component('Navi',navi)
app.component('Tabbar',tab_bar)

app.use(store).use(router).mount('#app')
// app.use(new VueSocketIO({
//   debug: true,    //  开启调试，方便查看socket状态，生产环境可关闭或删除
//   connection: 'http://localhost:3000'
// }))